#ifndef MS_INI_H
#define MS_INI_H

#include <stdint.h>

#include <map>
#include <string>
using namespace std;

/*
 * ini_section_t
 */
struct ini_section_t {
	typedef map<string, string> KeyValueMap;
	KeyValueMap key_values;
};

/*
 * ini_file_t
 */
struct ini_file_t {
	typedef map<string, ini_section_t*> SectionMapList;
	SectionMapList sections;

	ini_file_t() :
			file(NULL) {
	}

	~ini_file_t() {
		for (SectionMapList::iterator iter = sections.begin();
				iter != sections.end(); iter++) {
			delete (*iter).second;
		}
	}

	/*
	 * Don't use it!
	 */
	FILE* file;
};

/*
 * Enable INI File Cache
 */
bool EnableIniFileCache(bool enablecache);

/*
 * Enable Close INI File after Open Immediately
 */
bool EnableIniFileCloseWhenOpen(bool enableclose);

/*
 * Get INI File
 */
ini_file_t* GetIniFile(const string& filename);

/*
 * Get INI File Section
 */
ini_section_t* GetIniFileSection(const string& section, const string& filename);

/*
 * Get INI File String
 */
string GetIniFileString(const string& section, const string& key,
		const string& def, const string& filename);

/*
 * Get INI File Integer
 */
int32_t GetIniFileInt32(const string& section, const string& key, int32_t def,
		const string& filename);

/*
 * Get INI File String
 */
bool WriteIniFileString(const string& section, const string& key,
		const string& value, const string& filename);

/*
 * Get INI File String
 */
bool WriteIniFileInt32(const string& section, const string& key, int32_t value,
		const string& filename);

/*
 * Clear INI File Cache
 */
void ClearIniFileCache();

#endif /* MS_INI_H */
